package com.dao.impl;

import com.dao.OrderProductDao;
import com.pojo.OrderProduct;
import com.utils.JDBCUtil;

import java.util.List;

public class OrderProductDaoImpl implements OrderProductDao {

    /**
     * 排行版
     * @return
     */
    @Override
    public List<OrderProduct> rank() {
        return JDBCUtil.queryList(OrderProduct.class,"SELECT * FROM s_order_product GROUP BY product_id ORDER BY SUM(product_num) DESC LIMIT 6");
    }

    /**
     * 添加订单商品表
     * @param orderProduct
     * @return
     */
    @Override
    public int addOPD(OrderProduct orderProduct) {
        return JDBCUtil.update("insert into s_order_product values(?,?,?,?)",orderProduct.getId(),orderProduct.getOrderId(),orderProduct.getProductId(),orderProduct.getProductNum());
    }

    /**
     * 根据订单id查询订单商品表
     * @param orderID
     * @return
     */
    @Override
    public List<OrderProduct> selectByOrderID(String orderID) {
        return JDBCUtil.queryList(OrderProduct.class,"select * from s_order_product where order_id = ?",orderID);
    }
}
